#pragma once

#include <lifecycle_msgs/msg/state.hpp>
#include <lifecycle_msgs/srv/change_state.hpp>
#include <lifecycle_msgs/srv/get_state.hpp>
#include <map>
#include <rclcpp/rclcpp.hpp>
#include <rclcpp_lifecycle/rclcpp_lifecycle/lifecycle_node.hpp>

class Context
{
    using ChangeState = lifecycle_msgs::srv::ChangeState;
    using GetState = lifecycle_msgs::srv::GetState;

  public:
    enum NodeName
    {
        StateController,
        PathController,
        LocalPlaner,
    };

  private:
    std::map<NodeName, rclcpp::Client<ChangeState>::SharedPtr> set_clients;
    std::map<NodeName, rclcpp::Client<GetState>::SharedPtr> get_clients;
    std::map<NodeName, bool> is_active;
    std::weak_ptr<rclcpp::Node> node;

  public:
    Context(std::weak_ptr<rclcpp::Node> node, std::string prefix);
    void Initialize();
    void Finalize();
    void ChangeNodeState(NodeName name, uint8_t state);
    void ActiveNode(NodeName name);
    void DeactiveNode(NodeName name);
    bool IsActive(NodeName name);
    std::shared_ptr<rclcpp::Node> GetNode();
};